package com.asset.troubleticket.dao;

import java.util.List;
import java.util.Set;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.asset.troubleticket.domain.Authentication;

@Repository
public class AuthenticationDao {
	@Autowired
	SessionFactory sessionFactory;
	
	
	public void addAuthentication(Authentication auth){
		try{
			sessionFactory.getCurrentSession().save(auth);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	
	public void editAuthentication(Authentication auth){
		try{
			sessionFactory.getCurrentSession().saveOrUpdate(auth);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	public void deleteAuthentication(Authentication auth){
		try{
			sessionFactory.getCurrentSession().delete(auth);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	public Authentication getById(Integer id){
		try{
		return (Authentication)	sessionFactory.getCurrentSession().load(Authentication.class,id);
			}catch(Exception ex){
				ex.printStackTrace();
				return null;
			}
	}
	
	public List<Authentication> getAllAuthentications(){
		try{
			return sessionFactory.getCurrentSession().createQuery("from Authentication").list();
				}catch(Exception ex){
					ex.printStackTrace();
					return null;
				}
	}
}
